// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CIdResover.
//   $Id$
// IdResolver.h: interface for the CIdResolver class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_IDRESOLVER_H__4C58F5EB_F470_48B9_ADD0_91A69A614BA6__INCLUDED_)
#define AFX_IDRESOLVER_H__4C58F5EB_F470_48B9_ADD0_91A69A614BA6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <map>
class CImpl;
class CXFormsXFormsElement;
typedef std::map< CComBSTR,CImpl*> CMapBSTRToCImplPtr;
typedef std::pair< CComBSTR,CImpl*> CPairBSTRAndCImplPtr;

class CIdResolver  
{
public:
	void Remove(const BSTR sId);
	void ResetIterator();
	//returns false when the last id has been returned.
	bool IterateIds(BSTR * pbsRetVal);
	
	//adds an item to the list of scope resolvers
	HRESULT AddScopedId(BSTR sId, CImpl* pScopeContainer);
	//adds an item to the list of items in this scope.
	HRESULT AddItem(CImpl * pImpl);

	//retrieves an item based on the id.
	HRESULT getItem(const BSTR sId, CImpl*& pItem) const;

	CIdResolver(CImpl * pOwner, CXFormsXFormsElement * pOwnerForm);
	virtual ~CIdResolver();

private:

	//variables for iteration
	CMapBSTRToCImplPtr * m_pCurrentIteratorMap;
	CMapBSTRToCImplPtr::iterator m_IteratorPos;
	
	//Contains all identified nodes that are in direct
	//	scope of the owner of this resolver.
	CMapBSTRToCImplPtr m_NodeMap; 
	
	//Contains all ids of controls that are in scope
	//	of a node that is in scope of the owner of this
	//	resolver
	CMapBSTRToCImplPtr m_ScopeMap; 

	//maintain a pointer to the owner
	//	in order to run up the tree in
	//	search of ids scoped at a higher level.
	CImpl * m_pOwner;
	
	//The owner form is also pointed to 
	//	this is the owner if m_pOwner is NULL
	CXFormsXFormsElement * m_pOwnerForm;


};

#endif // !defined(AFX_IDRESOLVER_H__4C58F5EB_F470_48B9_ADD0_91A69A614BA6__INCLUDED_)
